package com.neuedu.it.teach.service.impl;

import com.neuedu.it.teach.dao.HelpDao;
import com.neuedu.it.teach.dao.OrderDao;
import com.neuedu.it.teach.dao.StudentInfoDao;
import com.neuedu.it.teach.entity.StudentInfo;

import com.neuedu.it.teach.service.StudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentInfoServiceImpl implements StudentInfoService {

    @Autowired
    private StudentInfoDao mapper;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private HelpDao helpDao;

    @Override
    public void addStudent(StudentInfo studentInfo) {
        mapper.insertStudent(studentInfo);
    }

    @Override
    public List<StudentInfo> getAllStudents() {
        return mapper.selectAllStudents();
    }

    @Override
    public List<StudentInfo> getStudentsByUserId(Integer userId) {
        return mapper.selectStudentsByUserId(userId);
    }

    @Override
    public void deleteStudent(Integer studentId) {
        // 1. 删除与该学生相关的互助信息（order_status 会自动被级联删除）
        helpDao.deleteHelpsByStudentId(studentId);

        // 2. 删除学生本身
        mapper.deleteStudentById(studentId);
    }

    @Override
    public void updateStudent(StudentInfo studentInfo) {
        mapper.updateStudent(studentInfo);
    }

    @Override
    public StudentInfo getStudentById(Integer studentId) {
        return mapper.selectStudentsByStudentId(studentId);
    }
}
